package com.smbms.mapper.impl;

import com.smbms.domain.SmbmsBill;
import com.smbms.mapper.SmbmsBillMapper;
import com.smbms.mapper.SmbmsUserMapper;
import com.smbms.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @ClassName SmbmsBillMapperImpl
 * @Description TODO:
 * @Author 12994
 * @Date 2024/10/18 23:06
 * @Version 1.0
 **/
public class SmbmsBillMapperImpl implements SmbmsBillMapper {
    SqlSession sqlSession;

    @Override
    public ArrayList<SmbmsBill> listSmbmsBill(SmbmsBill smbmsBill, Integer pages, Integer count, Date start, Date end) {
        try {
            sqlSession = MybatisUtil.getSqlSession();
            return sqlSession.getMapper(SmbmsBillMapper.class).listSmbmsBill(smbmsBill, (pages - 1) * count, count, start, end);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            MybatisUtil.releaseSqlSession(sqlSession);
        }
    }

    @Override
    public int removeSmbmsBillByIdList(ArrayList<String> idList) {
        try {
            sqlSession = MybatisUtil.getSqlSession();
            return sqlSession.getMapper(SmbmsBillMapper.class).removeSmbmsBillByIdList(idList);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            MybatisUtil.releaseSqlSession(sqlSession);
        }
    }


    public static void main(String[] args) {
        SmbmsBillMapper smbmsBillMapper = new SmbmsBillMapperImpl();

        SmbmsBill smbmsBill = new SmbmsBill();
        String startStr = "2014-12-14 10:10:10";
        String endStr = "2015-12-30 10:10:10";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        smbmsBill.setBillCode("00");
        Date start = null;
        Date end = null;
        try {
            start = format.parse(startStr);
            end = format.parse(endStr);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        smbmsBillMapper.listSmbmsBill(smbmsBill, 1, 5, start, end).forEach(System.out::println);

//        System.out.println("\n\n");
//        ArrayList<String> arrayList = new ArrayList<>();
//        arrayList.add("BILL2016_009");
//        arrayList.add("BILL2016_010");
//        smbmsBillMapper.removeSmbmsBillByIdList(arrayList);

    }
}
